package com.smartlib.cmnObject.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * @author hewenwen
 * @description <app 的工具类>
 * @date 2016/4/24
 */
public class AppUtil
{
    /***
     * 获取应用versionCode
     *
     * @param context
     * @return
     */
    public static int getVersionCode(Context context)
    {
        try
        {
            PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return pi.versionCode;
        }
        catch (PackageManager.NameNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return 0;
        }
    }

    /***
     * 获取应用的VersionName
     *
     * @param context
     * @return
     */
    public static String getVersionName(Context context)
    {
        try
        {
            PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return pi.versionName;
        }
        catch (PackageManager.NameNotFoundException e)
        {
            e.printStackTrace();
            return "";
        }
    }


}
